package com.jzo2o.orders.dispatch.demo;

import com.jzo2o.orders.dispatch.model.dto.ServeProviderDTO;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 按距离排序
 *
 * @author Mr.Z
 * @version 1.0
 * @date 2023/11/24 5:58
 */
public class AcceptNumRule extends AbstractProcessRule {

	public AcceptNumRule(IProcessRule next) {
		super(next);
	}

	/**
	 * 获取接单数最少的服务人员列表
	 *
	 * @param: serveProviderDTOS
	 * @return:
	 */
	@Override
	public List<ServeProviderDTO> doFilter(List<ServeProviderDTO> serveProviderDTOS) {
		// 找到接单数最少的一个服务人员
		ServeProviderDTO serveProviderDTO = serveProviderDTOS.stream()
			.min(Comparator.comparing(ServeProviderDTO::getAcceptanceNum))
			.get();
		// 找跟接单数最少的服务人员接单数一样的服务人员
		return serveProviderDTOS.stream()
			.filter(v -> v.getAcceptanceNum().equals(serveProviderDTO.getAcceptanceNum()))
			.collect(Collectors.toList());
	}

}
